package com.fy56.platform.fileupload.servlet;



import com.fy56.platform.fileupload.ActionEnter;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class UploadServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.addHeader("Access-Control-Allow-Origin",
                "*");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.addHeader("Access-Control-Allow-Origin","*");
        PrintWriter out = response.getWriter();
        // 获取当前绝对路径
//        String rootPath = request.getSession().getServletContext().getRealPath("/")+"WEB-INF/classes";
        String rootPath = request.getSession().getServletContext().getRealPath("/");



        out.write(new ActionEnter(request, rootPath).exec());

    }



    @Override
    protected void doOptions(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.addHeader("Access-Control-Allow-Origin","*");
        response.addHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
        response.addHeader("Access-Control-Max-Age", "50");
        response.addHeader("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With");

    }
}